package com.qq.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qq.bean.Friend;
import com.qq.bean.FriendshipVO;
import com.qq.bean.Users;
import com.qq.dao.UsersDao;
import com.qq.dao.impl.UsersDaoImpl;
import com.qq.service.UserService;
import com.qq.service.UsersService;

public class UsersServiceImpl implements UsersService{

	private UsersDao usersDao = new UsersDaoImpl();
	
	@Override
	public List<Users> getAllUsers() {
		
		return usersDao.selectAllUsers();
	}

	@Override
	public Map<String,Object> usersLogin(String account, String password) {
		Map<String,Object> map = new HashMap();
		Users loginUser = usersDao.selectUsers(account, password);
		
		if(loginUser != null) {
			map.put("loginUser",loginUser);
		}else {
			loginUser = usersDao.selectUsersByUsersname(account);
			if(loginUser == null) {
				map.put("msg","账号不存在");
			}else {
				map.put("msg","密码错误");
			}
		}
		return map;
	}

	@Override
	public Users getUsersname(String account) {
		// TODO Auto-generated method stub
		return usersDao.selectUsersByUsersname(account);
	}

	@Override
	public int usersRegister(Users user) {
		if(usersDao.selectUsersByUsersname(user.getAccount())!=null) {
			return -1;
		}
		return usersDao.insertUsers(user);
	}

	@Override
	public List<FriendshipVO> selectMyFriend(String accout) {
		// TODO Auto-generated method stub
		return usersDao.selectMyFriend(accout);
	}

	@Override
	public Users selectAddFriendUsers(String account, String friendacoount) {
		// TODO Auto-generated method stub
		return usersDao.selectAddFriendUsers(account, friendacoount);
	}

	@Override
	public int updateUsersAvatar(String account, String avatar) {
		// TODO Auto-generated method stub
		return usersDao.updateUsersAvatar(account, avatar);
	}

	@Override
	public int insertMyself(Friend friend) {
		// TODO Auto-generated method stub
		return usersDao.insertFriend(friend);
	}

	@Override
	public List<Users> selectAll() {
		// TODO Auto-generated method stub
		return usersDao.selectAll();
	}

	@Override
	public int updateUsersbByAccount(Users user) {
		// TODO Auto-generated method stub
		return usersDao.updateUsersbByAccount(user);
	}

	@Override
	public int deleteUsersByAccount(String account) {
		// TODO Auto-generated method stub
		return usersDao.delectUsersByAccount(account);
	}

	


	
}
